#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include <stdio.h>
using namespace std;

void    diff_spin();
void    fun1();

int main()
{
    diff_spin();
//    fun1();
}
void diff_spin()
{
    ifstream sp("spin_sp");
    ifstream tdc("spin_tdc");
    string str_sp, str_tdc;
    long int line = 0 ;
    long int sum = 0;
    int min = 2000;
    int max = 2000;
    int ex = 0;
    double power_diff = 0;
    while ( getline(sp,str_sp) && getline(tdc, str_tdc))
    {
        long curr_sp = stol(str_sp);
        long curr_tdc = stol(str_tdc);
        long diff = curr_tdc - curr_sp;
        sum = sum + diff;
        line++;
        printf("%d\n", diff);
    }
    cout<<"avg:"<< sum/line << endl;


}


void fun1()
{
    ifstream in("a_sp1");
    string str;
    long int line = 0 ;
    long int sum = 0;
    int min = 2000;
    int max = 2000;
    int ex = 0;
    double power_diff = 0;
    while ( getline(in,str))
    {
        int curr = stoi(str);
        if (curr > 10000) { ex++;continue;}
        min = curr < min ? curr : min;
        max = curr > max ? curr : max;
        sum = sum + curr;
        line++;

        power_diff = power_diff + (curr - 13562) * (curr - 13562);
    }
    cout<<"avg:"<< sum/line <<"--min:"<< min << "--max:" << max<< "--std:" << sqrt( power_diff/(line-1)) << endl;
    printf("ex_has:%f\n", ex/(ex+line));
    printf("ex_has:%ld\n", line);
    printf("ex_has:%ld\n", ex);


}
